import { Body, Inject, Post, Provide } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { AgentRelationEntity } from '../../entity/agentRelation';
import { AgentRelationService } from '../../service/agent';
import { Get, Query } from '@midwayjs/core';

/**
 * 代理关系管理
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: AgentRelationEntity,
  service: AgentRelationService,
  pageQueryOp: {
    // keyWordLikeFields: ['remark'],
    fieldEq: ['level', 'parentAgentId', 'topAgentId'],
  },
})
export class AdminAgentRelationController extends BaseController {
  @Inject()
  agentService: AgentRelationService;

  // 查询代理关系
  @Get('/queryAgentRelation')
  async queryAgentRelation(@Body() body: {}) {
    const res = await this.agentService.queryAgentRelation(body);
    // console.log(res);
    return this.ok(res);
  }

  // 查询代理关系
  @Get('/queryAgentRelationV2')
  async queryAgentRelationV2(@Body() body: {}) {
    const res = await this.agentService.queryAgentRelationV2(body);
    // console.log(res);
    return this.ok(res);
  }

  // 获取代理商列表（新增代理商处使用）
  @Post('/getAgentList')
  async getAgentList(@Body() body: { type: number; functionType: string }) {
    const res = await this.agentService.getAgentList(body);
    console.log(body);
    return this.ok(res);
  }
  // 添加代理关系
  @Post('/addAgent')
  async addAgent(@Body() body: {}) {
    const res = await this.agentService.addAgent(body);
    return this.ok(res);
  }
  // 获取代理商订单（替换原代理商订单的page接口）
  @Post('/getAgentOrder')
  async getAgentOrder(@Body() body: {}) {
    const res = await this.agentService.getAgentOrder(body);
    return this.ok(res);
  }
  // 代理商看板-全部
  @Post('/agentBoard')
  async agentBoard(@Body() body: {}) {
    const res = await this.agentService.agentBoard(body);
    return this.ok(res);
  }
  // 代理商看板
  @Post('/agentShopBoard')
  async agentShopBoard(@Body() body: {}) {
    const res = await this.agentService.agentShopBoard(body);
    return this.ok(res);
  }
  // 编辑代理关系
  @Post('/updateAgent')
  async updateAgent(@Body() body: {}) {
    const res = await this.agentService.updateAgent(body);
    return this.ok(res);
  }
  // 查询代理商信息
  @Post('/queryAgentById')
  async queryAgentById(@Body() body: { agentUserId: number }) {
    const res = await this.agentService.queryAgentById(body);
    return this.ok(res);
  }
  // 查询代理商铺
  @Post('/queryAgentShopById')
  async queryAgentShopById(@Body() body: { ShopIds: number[] }) {
    const res = await this.agentService.queryAgentShopById(body);
    return this.ok(res);
  }
  // 代理商商铺信息
  @Post('/getAgentShopList')
  async getAgentShopList(@Body() body: {}) {
    const res = await this.agentService.getAgentShopList(body);
    return this.ok(res);
  }

  // 获取登录人店铺订单
  @Post('/getOrderShopList')
  async getOrderShopList() {
    const res = await this.agentService.getOrderShopList();
    return this.ok(res);
  }

  // 获取一级代理商数组，联查出姓名
  @Get('/getLevelAgents')
  async getLevelAgents(@Query() query: { level?: number }) {
    const res = await this.agentService.getLevelAgents(query.level);
    return this.ok(res);
  }

  // 根据一级代理商查出二级代理商
  @Get('/getSecondLevelAgents')
  async getSecondLevelAgents(@Query() query: { firstAgentId: number }) {
    const res = await this.agentService.getSecondLevelAgents(query.firstAgentId);
    return this.ok(res);
  }

  // 查询代理商所有店铺信息
  @Post('/getAgentShopInfoAll')
  async getAgentShopInfoAll(@Body() body: {}) {
    const res = await this.agentService.getAgentShopInfoAll(body);
    return this.ok(res);
  }
}
